class RenderState{
    lineWidth = 1
    fillStyle = "red"
    strokeStyle = "green"

    clone():RenderState{
        let state = new RenderState();
        state.lineWidth = this.lineWidth;
        state.strokeStyle = this.strokeStyle;
        state.fillStyle = this.fillStyle
        return state;
    }

    toString(){
        return JSON.stringify(this,null," ")
    }
}

class RenderStateStack{
    private _statck:RenderState[] = [new RenderState()]
    private get _currentState(){
        return this._statck[this._statck.length - 1]
    }

    save(){
        this._statck.push(this._currentState.clone())
    }
    restore(){
        this._statck.pop();
    }

    get lineWidth(){
        return this._currentState.lineWidth;
    }
    set lineWidth(value:number){
        this._currentState.lineWidth = value
    }
    get strokeStyle(){
        return this._currentState.strokeStyle;
    }
    set strokeStyle(value:string){
        this._currentState.strokeStyle = value
    }
    get fillStyle(){
        return this._currentState.fillStyle
    }
    set fillStyle(value:string){
        this._currentState.strokeStyle = value
    }

    printCurrentStateInfo(){
        console.log(this._currentState.toString())
    }

}

export{
    RenderState,
    RenderStateStack
}